home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d27
/
bfrcmp.arc
/
BFRCMP.ASM
next >
Wrap
Assembly Source File
|
1990-06-03
|
2KB
|
76 lines
PAGE ,132
TITLE c Buffer Comparison
% .MODEL memmodel,C ; will generate proper code for any model
COMMENT $
This function compares the contents of two buffers and returns the position
where the first mismatch occurs in the buffer pair. The buffers are examined
on a byte-by-byte basis. Nothing is destroyed except AX which contains 0 if
nothing is different or the byte subscript of the difference. Bytes are
numbered from 1 to n (although c always numbers them from 0 to n-1) for this
function's purpose. If you need the offending byte in the c program array
subtract 1 from the return value.
This is a little tutorial piece on how to interface MASM 5.1 with C 5.1 because
the manuals only consider that you need to know how to add two scaler values.
If you were familiar with coding in assembly language you would have almost no
use for the manuals supplied by Microsoft.
use:
short (or int) bufcmp(ptr_string1, ptr_string2, nr_elements_to_compare)
returns:
0 - if all are equal
n - point at which they don't compare
note that if the array is not single bytes, you should do a multiply
of the number of elements to compare by the array element size and
use that value as the third argument. Bfrcmp treats the first two
arguments as if they were char *ptr but will respect them as if they
were void *ptr.
Programmed by A. L. Bender, M. D.
This is in the public domain and may be freely used by anyone for any
purpose including the manufacture of derivative works. In other words
it is freeware. I'm not responsible for any damages that you might
incur in its use and other comments from my fussypants lawyer.
$ .TABSIZE 8 ; if TASM
.CODE
bfrcmp PROC USES SI DI CX ,arg1:PTR, arg2:PTR, arg3:WORD
IF @DataSize
push ds
push es
ENDIF
pushf ; save the flags
mov cx,arg3 ; considered to be unsigned
test cx,cx ; test for zero length compare
jz done ; its ok to do that you know
IF @DataSize ; for other models
lds si, arg1 ; large, chiefly
les di, arg2
ELSE
mov si, arg1 ; small, chiefly
mov di, arg2
ENDIF
cld ; forward
repe cmpsb ; string compare, byte by byte
jnz @F ; it didn't match
done: xor ax,ax ; it did, or zero length compare
jmp short exit
@@: mov ax, arg3 ; figure where it stopped
sub ax, cx ; will be off by one (desired)
exit: popf ; restore them
IF @DataSize
pop es
pop ds
ENDIF
ret ; return to user code
bfrcmp ENDP
END